#ifndef XML_OPT_H
#define XML_OPT_H

#include "mytype.h"
#include "steam_out.h"

#ifdef __cplusplus
extern "C"
{
#endif

    typedef stream_out_type xml_opt_type;

#define xml_puts(str) stream_out_puts(xml, str)
#define xml_fmt(fmt, ...) stream_out_fmt(xml, fmt, ##__VA_ARGS__)

#define xml_opt_init(out_buff, out_buff_size, out_func) \
    stream_out_init(xml, out_buff, out_buff_size, out_func)

#define xml_opt_reset() stream_out_reset(xml)

#define xml_end() stream_out_end(xml)

#define xml_html_start() xml_puts("<!DOCTYPE HTML> <html>");

#define xml_html_end()    \
    xml_puts(" </html>"); \
    stream_out_end(xml);

#define xml_head_start(title)                         \
    do                                                \
    {                                                 \
        xml_puts(" <head> <meta charset=\"utf-8\">"); \
        xml_puts(" <title>");                         \
        if (title != NULL)                            \
        {                                             \
            xml_puts(title);                          \
        }                                             \
        xml_puts("</title>");                         \
    } while (0)

#define xml_head_end() xml_puts(" </head>")

#define xml_css_start(class_name) \
    xml_puts(" .");               \
    xml_puts(class_name);         \
    xml_puts("{")

#define xml_css_attr_add(attr_name, attr_value) \
    do                                          \
    {                                           \
        xml_puts(" ");                          \
        xml_puts(attr_name);                    \
        xml_puts(": ");                         \
        xml_puts(attr_value);                   \
        xml_puts(";");                          \
    } while (0)

#define xml_css_end() xml_puts("}")

    void xml_lable_add(xml_opt_type *opt, const char *label_name, void (*attribute)(void), void (*content)(void));

    void xml_lable_content_add(xml_opt_type *opt, const char *label_name, const char *attribute, void (*content)(void));

#define xml_lable_start(label_name) \
    xml_puts("<");                  \
    xml_puts(label_name);           \
    xml_puts(">")

#define xml_lable_end(label_name) \
    xml_puts("</");               \
    xml_puts(label_name);         \
    xml_puts(">") 

#define xml_lable_open(label_name) \
    xml_puts("<");                 \
    xml_puts(label_name);

#define xml_lable_close() xml_puts(">");

#define xml_lable_attr_add(attr_name, attr_value) \
    xml_puts(" ");                                \
    xml_puts(attr_name);                          \
    xml_puts("=\"");                              \
    xml_puts(attr_value);                         \
    xml_puts("\"");

#define xml_lable_attr_number_add(attr_name, attr_value, ipn) \
    do                                                        \
    {                                                         \
        char buff[32];                                        \
        i32_to_string(buff, attr_value, sizeof(buff), ipn);   \
        xml_lable_attr_add(attr_name, buff);                  \
    } while (0)

#define xml_lable_attr_begin(attr_name) \
    xml_puts(" ");                      \
    xml_puts(attr_name);                \
    xml_puts("=\"");

#define xml_lable_attr_end() xml_puts("\"");

#define xml_put_number(number, ipn, prefix, suffix) \
    do                                              \
    {                                               \
        char buff[32];                              \
        if (prefix != NULL)                         \
        {                                           \
            xml_puts(prefix);                       \
        }                                           \
        i32_to_string(buff, number, ipn, 0x03);     \
        xml_puts(buff);                             \
        if (suffix != NULL)                         \
        {                                           \
            xml_puts(suffix);                       \
        }                                           \
    } while (0)

#ifdef __cplusplus
} 
#endif 

#endif 